

<ul>
<?php

$username = $_GET["username"];
$post_data = array ( 'source' => ('ruocaled') );
$progress = 'http://api.bgm.tv/user/'.$username.'/collection?cat=watching';
//$progress = 'http://api.bgm.tv/calendar';
$result = curl_post($progress,$post_data);

$json = json_decode($result);
$count = 0;
$interest = 0;
$sex = 0;
$age = 0;
$ap = array();
$ap['交响诗篇AO'] = 29259; //交响诗篇AO
$ap['这就是僵尸吗第二季'] = 18797; //这就是僵尸吗？ 第二季
$ap['散华礼弥'] = 28230;
$ap['Fate/Zero第二季'] = 10639;
$ap['圣斗士星矢Ω'] = 33446;
$ap['ZETMAN'] = 24738;	
$ap['黄昏少女×失忆'] = 29060;
$ap['加速世界'] = 23685;
$ap['最强会长黑神'] = 23683;
$ap['谜之彼女X'] = 29323;
$ap['潜行吧!奈亚子'] = 24508;
$ap['天才麻将少女阿知贺篇'] = 24165;
$ap['黑子的篮球'] = 23684;
$ap['夏色奇迹'] = 26825;
$ap['OZUMA'] = 31417;	
$ap['宇宙兄弟'] = 28533;
$ap['希望宅邸'] = 26987;	
$ap['女皇之刃 叛乱'] = 33354;
$ap['火影忍者外传 李洛克的青春FULL POWER忍传'] = 28496;	
$ap['银河KICK OFF！！'] = 31374;
$ap['黑魔女学园'] = 35867;	
$ap['白熊咖啡馆'] = 32318;
$ap['战国Collection'] = 33355;	
$ap['美妙旋律 Dear My Future'] = 32816;
$ap['枪械少女'] = 27334;	
$ap['军火女王'] = 29073;	
$ap['钓球'] = 33255;
$ap['冰菓'] = 27364;	
$ap['AKB0048'] = 27317;
$ap['光明之心-幸福的面包'] = 28697;	
$ap['一起一起这里那里'] = 28431;
$ap['绯色的欠片'] = 29072;	
$ap['少年同盟二季'] = 29421;
$ap['坂道上的阿波罗'] = 29426;	

$ap['小恐龙阿贡'] = 36131;	
$ap['卡片战斗先导者 亚洲巡回赛篇'] = 35977;	
$ap['Phi-Brain～神之谜题 2'] = 31414;

$list = array();

$data = array();
$data['9774'] = array($ap['这就是僵尸吗第二季'],$ap['散华礼弥'],$ap['潜行吧!奈亚子'],$ap['黑魔女学园'],$ap['战国Collection'],$ap['枪械少女']);//这就是僵尸吗？
$data['12620'] = array($ap['交响诗篇AO'],$ap['ZETMAN'],$ap['OZUMA']); //创圣的大天使
$data['10462'] = array($ap['交响诗篇AO'],$ap['ZETMAN'],$ap['潜行吧!奈亚子'],$ap['OZUMA'],$ap['OZUMA'],$ap['宇宙兄弟'],$ap['宇宙兄弟'],$ap['军火女王'],$ap['坂道上的阿波罗'],$ap['Fate/Zero第二季']); //宇宙暴力海贼
$data['21900'] = array($ap['交响诗篇AO'],$ap['黄昏少女×失忆'],$ap['加速世界'],$ap['最强会长黑神'],$ap['天才麻将少女阿知贺篇'],$ap['夏色奇迹'],$ap['OZUMA'],$ap['黑魔女学园'],$ap['枪械少女'],$ap['AKB0048'],$ap['坂道上的阿波罗'] ); //轮回的格拉朗日
$data['23537'] = array($ap['白熊咖啡馆'],$ap['白熊咖啡馆'],$ap['白熊咖啡馆'],$ap['小恐龙阿贡'],$ap['小恐龙阿贡']); //嘟嘟猫观察日记
$data['20113'] = array($ap['希望宅邸']); //HIGH SCORE
$data['20851'] = array($ap['Fate/Zero第二季'],$ap['散华礼弥'],$ap['黄昏少女×失忆'],$ap['谜之彼女X'],$ap['谜之彼女X'],$ap['夏色奇迹'],$ap['坂道上的阿波罗'] ,$ap['冰菓'] ); //Another
$data['22657'] = array($ap['黄昏少女×失忆'],$ap['谜之彼女X'],$ap['夏色奇迹'] ,$ap['黑魔女学园'],$ap['Fate/Zero第二季']); //在盛夏等待
$data['23495'] = array($ap['钓球'],$ap['小恐龙阿贡'],$ap['夏色奇迹']); //夏目友人帐 第四季
$data['24790'] = array($ap['潜行吧!奈亚子'],$ap['希望宅邸']); //男子高校生の日常
$data['25444'] = array($ap['散华礼弥'],$ap['黄昏少女×失忆'],$ap['加速世界'],$ap['夏色奇迹'],$ap['女皇之刃 叛乱'],$ap['枪械少女'],$ap['冰菓'],$ap['AKB0048']); //听爸爸的话！
$data['12332'] = array($ap['卡片战斗先导者 亚洲巡回赛篇'],$ap['卡片战斗先导者 亚洲巡回赛篇']); //纸箱战机
$data['22679'] = array($ap['天才麻将少女阿知贺篇'],$ap['天才麻将少女阿知贺篇'],$ap['光明之心-幸福的面包'],$ap['绯色的欠片'],$ap['钓球']); //新网球王子
$data['20582'] = array($ap['散华礼弥'],$ap['黄昏少女×失忆'],$ap['潜行吧!奈亚子'],$ap['黑魔女学园'],$ap['冰菓']); //妖狐×仆SS
$data['20799'] = array($ap['潜行吧!奈亚子'],$ap['枪械少女'],$ap['枪械少女'],$ap['冰菓']); //爱杀宝贝
$data['22179'] = array($ap['散华礼弥'],$ap['黄昏少女×失忆'],$ap['加速世界'],$ap['最强会长黑神'],$ap['谜之彼女X'],$ap['夏色奇迹'],$ap['女皇之刃 叛乱'],$ap['黑魔女学园'],$ap['冰菓'],$ap['Fate/Zero第二季']); //黑岩射手
$data['22287'] = array($ap['夏色奇迹']); //侦探歌剧 Milky Holmes 第二幕
$data['23386'] = array($ap['希望宅邸']); //竖笛与双肩书包
$data['24649'] = array($ap['夏色奇迹']); //圣诞之吻SS+ plus
$data['28687'] = array($ap['希望宅邸']); //罗马浴场
$data['25834'] = array($ap['Fate/Zero第二季'],$ap['加速世界'],$ap['最强会长黑神'],$ap['谜之彼女X'],$ap['夏色奇迹'],$ap['黑魔女学园'],$ap['战国Collection'],$ap['军火女王'],$ap['冰菓'],$ap['AKB0048'] ); //战姬绝唱SYMPHOGEAR
$data['23161'] = array($ap['Fate/Zero第二季'],$ap['黄昏少女×失忆'],$ap['黄昏少女×失忆'],$ap['谜之彼女X'],$ap['潜行吧!奈亚子'],$ap['女皇之刃 叛乱'],$ap['冰菓']); //伪物语
$data['25823'] = array($ap['黄昏少女×失忆'],$ap['散华礼弥'],$ap['加速世界'],$ap['最强会长黑神'],$ap['潜行吧!奈亚子']); //零之使魔F
$data['26229'] = array($ap['黑子的篮球'],$ap['黑子的篮球'],$ap['银河KICK OFF！！'],$ap['绯色的欠片'],$ap['钓球']); //足球骑士
$data['15910'] = array($ap['光明之心-幸福的面包'],$ap['光明之心-幸福的面包'],$ap['冰菓'],$ap['Fate/Zero第二季'],$ap['枪械少女'],$ap['散华礼弥'],$ap['黄昏少女×失忆'],$ap['加速世界'],$ap['最强会长黑神'],$ap['谜之彼女X'],$ap['女皇之刃 叛乱'],$ap['女皇之刃 叛乱'],$ap['黑魔女学园'],$ap['战国Collection']); //High School D×D
$data['13485'] = array($ap['冰菓'],$ap['黑子的篮球'],$ap['黑子的篮球'],$ap['黑子的篮球'],$ap['枪械少女']); //萝球社
$data['10338'] = array($ap['钓球'],$ap['少年同盟二季'],$ap['绯色的欠片']);//学园救援团
$data['10760'] = array($ap['圣斗士星矢Ω'],$ap['银河KICK OFF！！']);//游戏王ZEXAL
$data['11834'] = array($ap['Fate/Zero第二季']);//银魂'
$data['14220'] = array($ap['钓球'],$ap['钓球'],$ap['绯色的欠片'],$ap['少年同盟二季'],$ap['少年同盟二季'],$ap['少年同盟二季'],$ap['少年同盟二季']);//少年同盟
$data['18004'] = array($ap['黄昏少女×失忆'],$ap['天才麻将少女阿知贺篇'],$ap['夏色奇迹'],$ap['黑魔女学园'],$ap['战国Collection'],$ap['枪械少女'],$ap['冰菓']); //侵略！？乌贼娘 二期
$data['18605'] = array($ap['夏色奇迹'],$ap['夏色奇迹']); //玉响～1年～
$data['22849'] = array($ap['黄昏少女×失忆'],$ap['加速世界'],$ap['最强会长黑神'],$ap['潜行吧!奈亚子'],$ap['黑魔女学园'],$ap['战国Collection'],$ap['冰菓']); //魔法小恶魔！
$data['23056'] = array($ap['钓球'],$ap['绯色的欠片'],$ap['绯色的欠片']); //战国☆天堂-极-
$data['1600'] = array($ap['钓球'],$ap['绯色的欠片']); //死神
$data['12557'] = array($ap['钓球']); //纯白交响曲
$data['18294'] = array($ap['Fate/Zero第二季'],$ap['天才麻将少女阿知贺篇'],$ap['军火女王'],$ap['坂道上的阿波罗'] ); //花牌情缘
$data['21580'] = array($ap['散华礼弥'],$ap['天才麻将少女阿知贺篇'],$ap['最强会长黑神'],$ap['女皇之刃 叛乱'],$ap['女皇之刃 叛乱'],$ap['战国Collection']); //魔具少女！
$data['24056'] = array($ap['天才麻将少女阿知贺篇'],$ap['希望宅邸']); //森田同学很沉默 2
$data['10526'] = array($ap['希望宅邸']); //我叫MT[第四季]
$data['12332'] = array($ap['银河KICK OFF！！']); //纸箱战机
$data['16594'] = array($ap['银河KICK OFF！！'],$ap['银河KICK OFF！！']); //闪电十一人GO
$data['3425'] = array($ap['火影忍者外传 李洛克的青春FULL POWER忍传'],$ap['火影忍者外传 李洛克的青春FULL POWER忍传'],$ap['火影忍者外传 李洛克的青春FULL POWER忍传'],$ap['银河KICK OFF！！']); //火影忍者
$data['8401'] = array(); //神奇宝贝超级愿望
$data['9779'] = array(); //恶魔奶爸
$data['10436'] = array($ap['钓球']); //战国鬼才传
$data['11577'] = array($ap['天才麻将少女阿知贺篇'],$ap['夏色奇迹'],$ap['夏色奇迹'],$ap['黑魔女学园'],$ap['冰菓'],$ap['AKB0048'],$ap['AKB0048'],$ap['AKB0048']); //偶像大师
$data['15489'] = array($ap['散华礼弥'],$ap['Fate/Zero第二季'],$ap['黑子的篮球']); //女神异闻录4
$data['17883'] = array($ap['散华礼弥'],$ap['Fate/Zero第二季'],$ap['天才麻将少女阿知贺篇'],$ap['夏色奇迹'],$ap['冰菓'],$ap['坂道上的阿波罗'] ); //我的朋友很少
$data['18624'] = array($ap['散华礼弥'],$ap['Fate/Zero第二季'],$ap['黑子的篮球'],$ap['黑魔女学园'],$ap['冰菓'],$ap['坂道上的阿波罗'] ); //回转企鹅罐
$data['18635'] = array($ap['散华礼弥'],$ap['Fate/Zero第二季'],$ap['谜之彼女X'],$ap['黑子的篮球'],$ap['坂道上的阿波罗'],$ap['冰菓']); //罪恶王冠
$data['18636'] = array($ap['坂道上的阿波罗'] ); //UN-GO
$data['1266'] = array($ap['交响诗篇AO'],$ap['军火女王'],$ap['坂道上的阿波罗'] ); //交响诗篇
$data['1759'] = array($ap['交响诗篇AO'],$ap['ZETMAN'],$ap['军火女王'],$ap['坂道上的阿波罗'] ); //交响诗篇剧场版
$data['12081'] = array($ap['交响诗篇AO'],$ap['ZETMAN'],$ap['夏色奇迹'],$ap['军火女王'],$ap['冰菓']); //最终流放-银翼的法姆-
$data['18631'] = array($ap['散华礼弥'],$ap['Fate/Zero第二季'],$ap['黄昏少女×失忆'],$ap['黑魔女学园'],$ap['战国Collection']); //灼眼的夏娜 第三季
$data['20813'] = array($ap['黑子的篮球'],$ap['钓球']); //世界一初恋2
$data['899'] = array(); //名侦探柯南
$data['2609'] = array(); //妖精的尾巴
$data['6756'] = array($ap['白熊咖啡馆'],$ap['白熊咖啡馆'],$ap['小恐龙阿贡'],$ap['小恐龙阿贡']); //来来猫
$data['10553'] = array(); //监狱兔 第4季
$data['10639'] = array($ap['Fate/Zero第二季'],$ap['Fate/Zero第二季'],$ap['Fate/Zero第二季'],$ap['坂道上的阿波罗'] ); //Fate/Zero
$data['11058'] = array($ap['散华礼弥'],$ap['黄昏少女×失忆'],$ap['谜之彼女X']); //认真和我恋爱！！
$data['12703'] = array($ap['散华礼弥'],$ap['黄昏少女×失忆'],$ap['谜之彼女X'],$ap['女皇之刃 叛乱'],$ap['黑魔女学园']); //境界线上的地平线
$data['18629'] = array($ap['散华礼弥'],$ap['黄昏少女×失忆'],$ap['女皇之刃 叛乱'],$ap['黑魔女学园']); //C3 -魔方少女-
$data['19540'] = array($ap['散华礼弥'],$ap['黄昏少女×失忆'],$ap['天才麻将少女阿知贺篇'],$ap['夏色奇迹'],$ap['黑魔女学园'],$ap['枪械少女'],$ap['冰菓']); //便·当
$data['20547'] = array($ap['冰菓'],$ap['冰菓'],$ap['冰菓']); //迷糊餐厅 第二季
$data['22241'] = array($ap['冰菓']); //向阳素描×SP
$data['22588'] = array($ap['钓球']); //食梦者 第二季
$data['975'] = array($ap['Fate/Zero第二季']); //海贼王
$data['10353'] = array($ap['Phi-Brain～神之谜题 2'],$ap['Phi-Brain～神之谜题 2'],$ap['Phi-Brain～神之谜题 2'],$ap['Phi-Brain～神之谜题 2']); //Phi-Brain～神之谜题
$data['10566'] = array(); //美食猎人TORIKO
$data['11779'] = array($ap['美妙旋律 Dear My Future'],$ap['美妙旋律 Dear My Future'],$ap['美妙旋律 Dear My Future']); //组曲光之美少女♪
$data['12192'] = array($ap['钓球']); //滑头鬼之孙～千年魔京～
$data['16235'] = array($ap['散华礼弥'],$ap['黄昏少女×失忆'],$ap['交响诗篇AO'],$ap['ZETMAN'],$ap['谜之彼女X'],$ap['谜之彼女X'],$ap['军火女王'],$ap['军火女王'],$ap['坂道上的阿波罗']); //未来日记
$data['18709'] = array($ap['圣斗士星矢Ω']); //机动战士高达AGE
$data['20407'] = array($ap['圣斗士星矢Ω'],$ap['银河KICK OFF！！'],$ap['卡片战斗先导者 亚洲巡回赛篇']); //战斗之魂 霸王
$data['20789'] = array($ap['圣斗士星矢Ω'],$ap['银河KICK OFF！！'],$ap['卡片战斗先导者 亚洲巡回赛篇']); //CROSS FIGHT 弹珠人
$data['21032'] = array($ap['圣斗士星矢Ω']); //猎人
$data['22507'] = array($ap['银河KICK OFF！！'],$ap['卡片战斗先导者 亚洲巡回赛篇']); //数码兽合体战争 穿越时空的少年猎人们

//print count($json);

get_result();

function get_result(){
	global $data,$sex,$age,$interest,$count,$json,$id,$username, $list, $ap;

	if (is_null($json)){
		echo '@'.$username.' 竟然没有在追新番。请仔细检查使用的是bangumi的用户id而不是昵称哦';
		return;
	}
	foreach ($json as $bangumi) {

	    $id = $bangumi -> {'subject'} -> {'id'};

		caculate($id,$username);
		 
	    
	}
	arsort($list);
	//var_dump($list);
	$i = 1;
	$name = array_search(key($list), $ap);
	if (!empty($name)){
		echo '<li>'.$i.'. <a href="http://bgm.tv/subject/'.key($list).'">'.$name.'</a></li>';
	} 
	foreach ($list as $todo){
		$i++;
		//echo $todo.'<br />';
		$name = array_search(key($list), $ap);
		//echo $name.'<br />';
		if (!empty($name)){
			echo '<li>'.$i.'. <a href="http://bgm.tv/subject/'.key($list).'">'.$name.'</a></li>';
		} 
		if ($i>9){
			break;
		}
		
	}

	//var_dump($list); 
	//echo $_SERVER['HTTP_REFERER'];
	//echo $interest.'|'.$sex.'|'.$age.'<br />';
	if ($count > 3){

		echo '<div id="small">*根据@'.$username.'在追的'.$count.'部有效新番所得出的结果，如果你觉得结果不够准确，<strike>那都是时臣的错。</strike></div>';

		//echo $a.'|'.$b.'|'.$c.'|';	
	}
	else{
		echo '<div id="small">@'.$username.' 在追的新番太少了，结果大概可能也许非常不准确。</div>';
		return;
	}

	
}


function caculate($id,$username){
	global $data,$sex,$age,$interest,$count,$list;
	if (array_key_exists($id, $data)){
/*		$interest = $interest + $data[$id][0];
		$sex = $sex + $data[$id][1];
		$age = $age + $data[$id][2];*/
		$count++;

		foreach ($data[$id] as $bangumi) {
			
			if (!empty($list[$bangumi])){
				$list[$bangumi]+= 10;
			}else{
				$list[$bangumi]=1;
			}
		}

	}
	else{
		//echo "$username<br/>";
	}

}

function curl_post($url, array $post = NULL, array $options = array()) 
{ 
    $defaults = array( 
        CURLOPT_POST => 1, 
        CURLOPT_HEADER => 0, 
        CURLOPT_URL => $url, 
        CURLOPT_FRESH_CONNECT => 1, 
        CURLOPT_RETURNTRANSFER => 1, 
        CURLOPT_FORBID_REUSE => 1, 
        CURLOPT_TIMEOUT => 4, 
        CURLOPT_POSTFIELDS => http_build_query($post) 
    ); 

    $ch = curl_init(); 
    curl_setopt_array($ch, ($options + $defaults)); 
    if( ! $result = curl_exec($ch)) 
    { 
        trigger_error(curl_error($ch)); 
    } 
    curl_close($ch); 
    return $result; 
} 




?>

</ul>

